package com.orange.modules.dao;

import java.sql.SQLException;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.orange.dbhelp.DbHelper;
import com.orange.modules.entity.school_data.AuthTeacherData;

@Repository
public class AuthTeacherDataRepository {
	
	@Resource(name = "dbHelper")
	private DbHelper dbHelper;
	
	@Autowired
	private AuthTeacherDataDao authTeacherDataDao;
	
	public void insertTeacherData(AuthTeacherData atd) throws SQLException{
		authTeacherDataDao.save(atd);
	}
	
	public AuthTeacherData queryAuthTeacherDataBySchoolId(String schoolId,String loginType) throws SQLException{
		String sql = "SELECT t.p_id as pid,t.s_fulltime_teacher_num as fulltimeTeacherNum,"
				+ "t.s_school_series_num as schoolSeriesNum,t.s_school_privatdozent_num as schoolPrivatdozentNum,"
				+ "t.s_professional_fulltime_teacher_num as professionalFulltimeTeacherNum,t.s_professional_series_num as professionalSeriesNum,"
				+ "t.s_professional_privatdozent_num as professionalPrivatdozentNum,t.s_higher_education_fulltime_teacher_num as higherEducationFulltimeTeacherNum,"
				+ "t.s_doctoral_teachers_num as doctoralTeachersNum,t.s_master_teachers_num as masterTeachersNum,"
				+ "t.s_master_ratio as masterRatio,t.s_high_professional_education_fulltime_teacher_num as highProfessionalEducationFulltimeTeacherNum,"
				+ "t.s_doctoral_degrees_num as doctoralDegreeNum,t.s_reading_doctoral_num as readingDoctoralNum,t.s_master_degree_num as masterDegreeNum,"
				+ "t.s_reading_master_num as readingMasterNum,t.s_senior_fulltime_teacher_num as seniorFulltimeTeacherNum,"
				+ "t.s_school_professor_num as schoolProfessorNum,t.s_school_associate_professor_num as schoolAssociateProfessorNum,"
				+ "t.s_professional_higher_fulltime_teacher_num as professionalHigherFulltimeTeacherNum,"
				+ "t.s_professional_professor_num as professionalProfessorNum,t.s_professional_associate_professor_num as professionalAssociateProfessorNum,"
				+ "t.s_professional_lecturer_num as professionalLecturerNum,t.s_oneyear_kindergarten_teachers_num as oneyearKindergartenTeachersNum,"
				+ "t.s_noyear_kindergarten_teachers_num as noyearKindergartenTeachersNum,t.s_excellent_teachers_num as excellentTeachersNum,t.s_createtime as createtime,"
				+ "t.s_id as sid,login_type as logintype,s_status as status,t.s_reading_doctoral_teachers_num as readingDoctoralTeachersNum,"
				+ "t.s_reading_master_teachers_num as readingMasterTeachersNum,t.s_remark as remark FROM  t_auth_teacher_data t WHERE t.s_id = ?";
	
		if(StringUtils.isNotBlank(loginType)){
			sql+="AND  t.login_type ='"+loginType+"'";
		}
		
		AuthTeacherData atd = dbHelper.getBean(sql, AuthTeacherData.class,schoolId);
		return atd;
	}

}
